package com.lc.pianostudent.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lc.pianostudent.R;
import com.lc.pianostudent.bean.PianoRecordBean;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/6/25.
 */

public class PianoRecordAdapter extends RecyclerView.Adapter<PianoRecordAdapter.ViewHolder>{


    private Context context;

    private List<PianoRecordBean> list = new ArrayList<>();

    public PianoRecordAdapter(Context context, List<PianoRecordBean> list) {
        this.context = context;
        this.list = list;
    }

    public interface OnItemClickListener {

        void onItemClick(View view, int position);

    }

    private PianoRecordAdapter.OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(PianoRecordAdapter.OnItemClickListener listener) {

        this.onItemClickListener = listener;

    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_piano_record, parent, false);

        ScaleScreenHelperFactory.getInstance().loadViewGroup((ViewGroup) view);

        PianoRecordAdapter.ViewHolder viewHolder = new PianoRecordAdapter.ViewHolder(view);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.content.setText("今日练琴"+list.get(position).getTime()+",认真指数"+list.get(position).getNumber()+",老师奖励我"+list.get(position).getXx()+"颗星"+","+list.get(position).getWealth()+"琴币，练琴"+list.get(position).getRenzhen()+"，手型"+list.get(position).getZhixing());

        holder.time.setText(list.get(position).getCreate_time());

        holder.status.setText("已完成");


        setUpItemEvent(holder,position);

    }

    //为RecyclerView添加点击事件
    protected void setUpItemEvent(final PianoRecordAdapter.ViewHolder holder, final  int position) {

        if (onItemClickListener != null) {

            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    //  int LayoutPosition = holder.getLayoutPosition();

                    onItemClickListener.onItemClick(holder.itemView, position);



                }

            });

        }

    }
    @Override
    public int getItemCount() {
        return list.size();
    }


    //初始化组件
    public static class ViewHolder extends RecyclerView.ViewHolder {

        public TextView content,time,status;


        public ViewHolder(View itemView) {
            super(itemView);

            content = (TextView) itemView.findViewById(R.id.content);
            time = (TextView) itemView.findViewById(R.id.time);
            status = (TextView) itemView.findViewById(R.id.status);

        }
    }
}
